<?php //pack11class

class VisitObjectPopup extends Module {

    public $width="400px";
    public $traceEnabled=true;
    public $cancel="Cancel";
    public $question="Undefined";
    public $submit="Submit";
    public $buttons="";
    public $address="";
    public $object_id="";

    public function setup() {
        $object=ObjectsManager::getCurrentObject();
        $this->object_id=$object->id;
        $this->question=LabelManager::getLabel("visit_object_label");
        $this->address=$object->label;
        $this->setID("VisitObjectPopup");
        $this->setClass("popup");
        $form=new VisitObjectForm;
        $form->setID("VisitObjectForm");
        $form->extra=LabelManager::getLabel("form_error_simple_alert");

        $name=new TextInput;
        $name->property_name="VisitorName";
        $name->setID("VisitorName");
        $name->label=LabelManager::getLabel("name_label");
        $form->addChild($name);

        $phone=new TextInput;
        $phone->property_name="VisitorPhone";
        $phone->setID("VisitorPhone");
        $phone->events='onkeydown="f(this)" onkeyup="f(this)" onblur="f(this)" onclick="f(this)"';
        $phone->label=LabelManager::getLabel("phone_label");
        $form->addChild($phone);

        $mail=new TextInput;
        $mail->property_name="VisitorMail";
        $mail->setID("VisitorMail");
        $mail->label=LabelManager::getLabel("mail_label");
        $form->addChild($mail);

        $time=new FromToSelect;
        $fromVariants=array("9:00","10:00","11:00","12:00","13:00","14:00","15:00","16:00","17:00","18:00","before","after");
        $toVariants=array("10:00","11:00","12:00","13:00","14:00","15:00","16:00","17:00","18:00","19:00");
        foreach($fromVariants as $item) {
            $option=new SelectOption;
            if($item=="before" || $item=="after") {
                $option->label=LabelManager::getLabel($item."_label");
                $option->value=($item=="before")? $fromVariants[0]:"after";
            } else {
                $option->label=$option->value=$item;
            }
            $option->selected=($item=="9:00")? SelectOption::SELECTED:"";
            array_push($time->from_variants,$option);
        }

        foreach($toVariants as $item) {
            $option=new SelectOption;
            $option->label=$item;
            $option->value=$item;
            $option->selected=($item=="10:00")? SelectOption::SELECTED:"";
            array_push($time->to_variants,$option);
        }

        $time->property_name="VisitorTime";
        $time->setID("VisitorTime");
        $time->label=LabelManager::getLabel("visitor_time_label");
        $time->from_action=$time->to_action=str_replace('\"', '"', "onChange=\"VisitObjectPopup.checkTime(this);\"");
        $time->draw();
        $form->addChild($time);

        $select=new SelectInput;
        $options=explode(",",LabelManager::getLabel("weekdays"));
        for($i=0; $i<count($options)-1; $i++) {
            $option=new SelectOption;
            $option->label=$option->value=$options[$i];
            if($i==0) $option->selected=SelectOption::SELECTED;
            $select->addChild($option);
        }
        $select->label=LabelManager::getLabel("popup_visit_day");
        $select->property_name="VisitorDay";
        $select->setID("VisitorDay");
        $select->class="select";
        $form->addChild($select);

        $right=new SimpleModule();
        $right->setID("SignContainer");

        $captcha = new SimpleModule();
        $captcha->setClass("CaptchaBlock");
        $cid=Captcha::setHash();
        $captcha->setBody(str_replace('\"','"',"<div id=\"captcha\"><img src=\"?response=CaptchaGenerator&cid=".$cid."\"/><input type=\"hidden\" id=\"cid\" name=\"cid\" value=\"".$cid."\"/></div>"));
        $right->addChild($captcha);

        $capt=new TextInput();
        $capt->setClass("CaptchaInput");
        $capt->property_name="c_value";
        $capt->id="c_value";
        $capt->label="Sequrity code: ";
        $right->addChild($capt);

        $item=new CheckBoxInput;
        $item->property_name="VisitorSign";
        $item->setID("VisitorSign");
        $item->label=LabelManager::getLabel("visitor_sign_label");
        $item->value="0";
        $item->events=str_replace('\"', '"', "onChange=\"VisitObjectPopup.setSign(this);\"");
        $right->addChild($item);

        $form->addChild($right);

        /*$spacer=new Spacer;
        $spacer->addStyle("height","20px");
        $form->addChild($spacer);*/

        $cancel=new FormButton;
        $cancel->value=LabelManager::getLabel("button_cancel");
        $cancel->type=FormButton::TYPE_BUTTON;
        $cancel->setID("VisitObjectCancel");
        $form->addButton($cancel);

        $save=new FormButton;
        $save->value=LabelManager::getLabel("button_send");
        $save->type=FormButton::TYPE_BUTTON;
        $save->setID("VisitObjectSubmit");
        $form->addButton($save);

        $this->buttons=$form->getButtons();
        $this->addChild($form);

    }

}
?>
